﻿@{
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section styles{

}
<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" lay-filter="dictype-form" style="padding: 15px 0 0 0;">

            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">父栏目</label>
                <div class="layui-input-block">
                   <input id="channelcascader" name="ParentId"/>

                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">栏目</label>
                <div class="layui-input-block">
                   <textarea name="Channels"  style="height:280px;"
                        placeholder="栏目之间用换行分割，下级栏目在栏目前添加“-”字符，索引可以放到括号中，如：
栏目一(栏目索引) 
-下级栏目(下级索引)
--下下级栏目" 
                       class="layui-textarea"></textarea>

                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label layui-form-required">名称为索引</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="IsIndexName" lay-skin="switch" >

                </div>
                 <div class="layui-form-mid layui-word-aux">将栏目名称作为栏目索引</div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-hide" lay-submit lay-filter="channel-submit" id="channel-submit">提交</button>
                </div>
            </div>
        </form>
    </div>
</div>


@section scripts{

    <script type="text/javascript">

        layui.use(['lscom', 'form', 'layCascader'], function () {
            var $ = layui.$;
            var lscom = layui.lscom;
            var form = layui.form;
            var dtree = layui.dtree;
            var layCascader = layui.layCascader;

            var index = parent.layer.getFrameIndex(window.name);
            //parent.layer.iframeAuto(index);

            lscom.ajax({
                url: "/Cms/Channel/GetChannleCascader?channelId=0",
                type:'GET',
                lsHandleError: false
            }).done(function(data) {
                if (data.code == 0) {
                    layCascader({
                        elem: '#channelcascader',
                        options: data.data,
                        clearable: true
                    });
                }
            }).fail(function(message) {
                lscom.notify.error(message);
            })

          
            form.render();
            window.submitForm = function () {
                $("#channel-submit").click();
            }

            form.on('submit(channel-submit)', function (data) {

                data.field.IsIndexName = data.field.IsIndexName == "on" ? 1 : 0;
                
                var field = data.field;

                var waitIndex = parent.layer.load(2);
                lscom.ajax({
                    url: "/Cms/Channel/SaveInsertData",
                    data: JSON.stringify(field),
                    lsHandleError: false
                }).done(function (data) {
                    if (data.code == 0) {
                        data.index = index;
                        let parentWindow = parent.selectedWindow().window;
                        parentWindow.saveCallback(data);
                    }
                }).fail(function (message) {
                    lscom.notify.error(message);
                }).always(function () {
                    parent.layer.close(waitIndex);
                });

                return false;
            });
        });
    </script>

}

